/*
The original code to manage and animate MD2 models was modified to allow non-repeating
animations as well as a callback registration function to allow some action to take
place upon termination of a non-repeating animation.






 *  Object3D.h
 *  MD2 File Loading
 *
 *  Created by Seth Willits on 9/11/04.
 *  Copyright 2004 Freak Software. All rights reserved.
 *
 */

#ifndef __OBJECT3D__
#define __OBJECT3D__
#include "MD2.h"
#include <vector>
#include "Platform.h"
#include "MovableObject.h"




///////////////////////////////////////////////////////////////////////////
//	Model States
//	
///////////////////////////////////////////////////////////////////////////

#define kO3DFrameStep 1.0 / 4.0


// Frame Animation States
typedef struct {
	int Start;
	int End;
} Object3DState;

enum {
	kIdle1,					// 0-39
	kIdle2,					// 74-95
	kIdle3,					// 113-122
	kIdle4,					// 123-135
	kRunning,				// 40-46
	kJumping,				// 67-73
	kShotBackBend,			// 47-60
	kShotShoulder,			// 61-66
	kCrouch,				// 136-154
	kCrouchCrawl,			// 155-161
	kCrouchIdle,			// 162-169
	kKneelingDying,			// 170-177
	kFallingBackDying,		// 178-185
	kFallingForwardDying,	// 186-190
	kFallingBackSlowDying	// 191-197
};




///////////////////////////////////////////////////////////////////////////
//	Object3D Class
//	
///////////////////////////////////////////////////////////////////////////

class Object3D
{
	public:
		bool repeat;

		// Constructor and Destructor
		Object3D(short pMaxModelCount, MovableObject* parent);
		//Object3D(short pMaxModelCount, void (*onAnimationFinish)(int state, Object3D* model));
		~Object3D();
		
		// Load Model
		bool LoadModel(char * pModelFile, char * pSkinFile);
		
		// Draw Model
		void Draw();
		void Update();
		
		// State Management
		void SetState(int pState, bool repeat);
		void ChangeState(int pState);
		int GetCurrentState();
		int GetNextState();
		
		
	private:
		//void (*finishEvent)(int state, Object3D* model);		// for animation finish
		MovableObject* object;

		short		mMaxModelCount;
		short		mModelCount;
		MD2Model **	mModels;
		
		int				mCurrentFrame;
		int				mNextFrame;
		float			mInterpolation;
		int				mCurrentStateIndex;
		int				mNextStateIndex;
		Object3DState	mCurrentState;
		Object3DState	mNextState;
};


#endif